package org.oos.dao.impl;

import static org.oos.ApiUrlProvider.UserLists;

import org.oos.atom.CategoryFeed;
import org.oos.atom.entries.CategoryEntry;
import org.oos.atom.entries.impl.CategoryEntryImpl;
import org.oos.atom.impl.CategoryFeedImpl;
import org.oos.dao.UserListsDao;
import org.oos.dao.lists.impl.ReadAllList;

import com.google.api.client.http.GenericUrl;

public class UserListsDaoImpl extends
		AbstractDao<CategoryEntry, CategoryFeed<CategoryEntry>> implements
		UserListsDao {

	private String userSlug;

	public UserListsDaoImpl() {
		super(CategoryFeedImpl.class, CategoryEntryImpl.class);
	}

	@Override
	protected GenericUrl getFeedUrl() {
		if (userSlug != null) {
			return UserLists.getUrl(userSlug);
		} else {
			throw new IllegalStateException("There must be a slug");
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	protected ReadAllList<CategoryEntry, CategoryFeed<CategoryEntry>> getList(CategoryFeed feed) {
		return new ReadAllList<CategoryEntry, CategoryFeed<CategoryEntry>>(this, feed);
	}

	@Override
	public void setUserSlug(String userSlug) {
		this.userSlug = userSlug;
	}

	@Override
	public String getContentType() {
		return "application/atomcat+xml";
	}
}
